<!-- 填写结算信息 -->
<template>
	<view style="padding-bottom: 160rpx;">
		<view class="p-3">
			<u--form errorType="toast" labelWidth="100" :labelStyle="{fontSize:'28rpx'}" labelPosition="left" :model="postData" :rules="rules" ref="uForm">
			
				<view>
					<bg-title class="mb-3">
						<text style="font-size: 30rpx;">项目结算信息</text>
					</bg-title>
					<view class="bt-block px-3">
						<u-form-item labelWidth="80" labelPosition="left" required label="项目编号">
							<view class="text-right flex-1">{{postData.projectNo}}</view>
						</u-form-item>
						<view class="bt-line-1" > </view>
						<u-form-item labelPosition="left" required label="项目名称">
							<view class="text-right flex-1">{{postData.projectName}}</view>
						</u-form-item>
						<view class="bt-line-1" > </view>
						<u-form-item labelWidth="100" labelPosition="left" required label="含税合同额">
							<view class="text-right flex-1">{{postData.contractAmount}}</view>
						</u-form-item>
						<view class="bt-line-1" > </view>
						<u-form-item labelPosition="left" required label="税率">
							<view class="text-right flex-1">3%</view>
						</u-form-item>
						<view class="bt-line-1" > </view>
						<u-form-item labelPosition="left" required label="税金">
							<view class="text-right flex-1">{{taxAmount}}</view>
						</u-form-item>
						<view class="bt-line-1" > </view>
						<u-form-item labelWidth="100" labelPosition="left" required label="劳务成本金额">
							<view class="text-right flex-1">{{postData.laborCosts}}</view>
						</u-form-item>
						<view class="bt-line-1" > </view>
						<u-form-item labelWidth="100" labelPosition="left" required label="材料成本金额">
							<view class="text-right flex-1">{{postData.materialCosts}}</view>
						</u-form-item>
						<view class="bt-line-1" > </view>
						<u-form-item required label="管理成本金额" labelWidth="100" prop="managementCosts">
							<u--input v-model="postData.managementCosts" border="none" inputAlign='right' placeholder="请输入"></u--input>
						</u-form-item>
						<view class="bt-line-1" > </view>
						<u-form-item required label="保险成本金额" prop="insuranceAmount" labelWidth="100">
							<u--input v-model="postData.insuranceAmount" border="none" inputAlign='right' placeholder="请输入"></u--input>
						</u-form-item>
						<view class="bt-line-1" > </view>
						<u-form-item required label="其他成本金额" prop="otherCosts" labelWidth="100">
							<u--input v-model="postData.otherCosts" border="none" inputAlign='right' placeholder="请输入"></u--input>
						</u-form-item>
						<view class="bt-line-1" > </view>
						<u-form-item required label="含税毛利金额" prop="grossProfitAmount" labelWidth="100">
							<u--input v-model="postData.grossProfitAmount" border="none" inputAlign='right' placeholder="请输入"></u--input>
						</u-form-item>
					</view>
				</view>
				<view class="mt-3">
					<bg-title class="mb-3">
						<text style="font-size: 30rpx;">项目收入明细</text>
					</bg-title>
					<view class="bt-block px-3">
						<u-form-item required label="含税已回款" prop="taxInclusiveReceivedPayment" labelWidth="100">
							<u--input v-model="postData.taxInclusiveReceivedPayment" border="none" inputAlign='right' placeholder="请输入"></u--input>
						</u-form-item>
						<view class="bt-line-1" > </view>
						<u-form-item required label="含税应收款" prop="taxInclusiveReceivablePayment" labelWidth="100">
							<u--input v-model="postData.taxInclusiveReceivablePayment" border="none" inputAlign='right' placeholder="请输入"></u--input>
						</u-form-item>
						<view class="bt-line-1" > </view>
						<u-form-item required label="已开票金额" prop="invoicedAmount" labelWidth="100">
							<u--input v-model="postData.invoicedAmount" border="none" inputAlign='right' placeholder="请输入"></u--input>
						</u-form-item>
						<view class="bt-line-1" > </view>
						<u-form-item required label="已开票未回款" prop="invoiceUnpaidAmount" labelWidth="100">
							<u--input v-model="postData.invoiceUnpaidAmount" border="none" inputAlign='right' placeholder="请输入"></u--input>
						</u-form-item>
					</view>
				</view>
			</u--form>
			<bg-confirm content="请再次确认填写信息是否准确无误"
			:show.sync="show" @confirm="confirmModal" @close="closeModal"
			></bg-confirm>
		</view>
		<view class="bt-footer">
			<bg-btn @click="saveData">保存</bg-btn>
		</view>
	</view>
</template>

<script>
	import {settlementProject, getSettleMentDetail} from "@/api/project.js"
	export default {
		onLoad(options){
			this.projectId = options.pid
			this.getData()
		},
		computed:{
			taxAmount(){
				return (this.postData.contractAmount*0.03).toFixed(2)
			}
		},
		data() {
			return {
				show:false,
				rules:{
					'managementCosts': {
						type: 'number',
						required: true,
						message: '请输入管理成本金额',
						trigger: ['blur', 'change']
					},
					'insuranceAmount': {
						type: 'number',
						required: true,
						message: '请输入保险成本金额',
						trigger: ['blur', 'change']
					},
					'otherCosts': {
						type: 'number',
						required: true,
						message: '请输入其他成本金额',
						trigger: ['blur', 'change']
					},
					'grossProfitAmount': {
						type: 'number',
						required: true,
						message: '请输入含税毛利金额',
						trigger: ['blur', 'change']
					},
					'taxInclusiveReceivedPayment': {
						type: 'number',
						required: true,
						message: '请输入含税已回款',
						trigger: ['blur', 'change']
					},
					'taxInclusiveReceivablePayment': {
						type: 'number',
						required: true,
						message: '请输入含税已回款',
						trigger: ['blur', 'change']
					},
					'invoicedAmount': {
						type: 'number',
						required: true,
						message: '已开票金额',
						trigger: ['blur', 'change']
					},
					'invoiceUnpaidAmount': {
						type: 'number',
						required: true,
						message: '请输入已开票未回款',
						trigger: ['blur', 'change']
					},
				},
				projectId:'',
				postData:{
					"id": 0,
					"projectNo": "",
					"projectName": "",
					"projectAddr": "",
					"projectScale": "",
					"contractAmount": "",
					"employer": "",
					"subcontractor": "",
					"projectManagerUserId": 0,
					"projectManagerUserName": "",
					"productionManagerUserId": 0,
					"productionManagerUserName": "",
					"chiefEngineerUserId": 0,
					"chiefEngineerUserName": "",
					"financeManagerUserId": 0,
					"financeManagerUserName": "",
					"projectAdminUserId": 0,
					"projectAdminUserName": "",
					"safetyManagerUserId": 0,
					"managementCosts": 0,
					"otherCosts": 0,
					"taxInclusiveReceivedPayment": 0,
					"taxInclusiveReceivablePayment": 0,
					"invoicedAmount": 0,
					"invoiceUnpaidAmount": 0,
					"isSettlement": "",
					"workerCount": 0,
					"materialCosts": 0,
					"laborCosts": 0,
					"grossProfitAmount": 0,
					"settlementTime": "",
					"insuranceAmount": 0
				}
			}
		},
		methods: {
			getData(){
				getSettleMentDetail(this.projectId).then(res=>{
					this.postData = res.data
				})
			},
			closeModal(){
				this.show = false;
			},
			confirmModal(){
				settlementProject(this.postData).then(res=>{
					this.$modal.msgSuccess(res.msg)
					uni.$emit("refresh-settle", true)
					this.$tab.navigateBackDelay()
				})
			},
			saveData(){
				this.$refs.uForm.validate().then(res=>{
					if(res){
						this.show = true
					}
				})
			}
		},
		watch:{
			"postData":{
				handler(newVal, oldVal){
					let a  = Number(newVal.laborCosts)||0
					let b  = Number(newVal.materialCosts)||0
					let c  = Number(newVal.insuranceAmount)||0
					let d  = Number(newVal.otherCosts)||0
					let e  = Number(newVal.managementCosts)||0
					let total = a+b+c+d+e
					newVal.grossProfitAmount = Number(newVal.contractAmount-total)||0
				},
				deep:true
			}
		}
	}
</script>

<style>

</style>
